// (C) 2022 Intel Corporation. All rights reserved.
// Your use of Intel Corporation's design tools, logic functions and other 
// software and tools, and its AMPP partner logic functions, and any output 
// files from any of the foregoing (including device programming or simulation 
// files), and any associated documentation or information are expressly subject 
// to the terms and conditions of the Intel Program License Subscription 
// Agreement, Intel FPGA IP License Agreement, or other applicable 
// license agreement, including, without limitation, that your use is for the 
// sole purpose of programming logic devices manufactured by Intel and sold by 
// Intel or its authorized distributors.  Please refer to the applicable 
// agreement for further details.

module RJO_TOP
    #(
        parameter JUMPER_COUNT  = 6'd48 
   
    )


( 
	input           Clock,
	input           Reset,
	input           FM_VAL_DBG_JUMPER_EN,
	input           T_Reset,
	input           iPLTRST_N,
	input           iSlpS3,
	input           iAUX_PWRGD_CPU,
	input  [ 7:0]   bidin,					//Bifurcation ID
	output [15:0]   bidout,				        //Bifurcation ID  
	
	
   	output   [JUMPER_COUNT+12-1:0]   JumperOut, 
	input    [JUMPER_COUNT+12-1:0]   JumperIn,

	input           iCPU0_MEM_Done,
	input           iCPU1_MEM_Done,
  	input           RSU_FlashBusy,	
	output          invalid_access,
	output                          FM_TTK_SPI_EN_RJC_N_Override        ,
	output                          PFR_DEBUG_JUMPER_RJC_N_Override     ,
	output                          PFR_FORCE_RECOVERY_RJC_N_Override   ,
	output                          FM_TTK_SPI_EN_RJC_N_Value           ,
	output                          PFR_DEBUG_JUMPER_RJC_N_Value        ,
	output                          PFR_FORCE_RECOVERY_RJC_N_Value      ,	 
	  //i2c_slave avmm intf
	  input  [31: 0]  avmm_address,      //Write/Read Address for writing to registers
    input  [31: 0]  avmm_writedata,    //Write Data for writing to registers
    input           avmm_write,        //Write Enable for marking Address and Data as valid to write
    input           avmm_read, 
    output          avmm_readvalid,
    output [31: 0]  avmm_readdata,      //Read Data for reading from registers
    output          avmm_waitrequest,
	  input   [3: 0]  avmm_byteenable,

    output          avmm_csr_addr,          
    output          avmm_csr_read,            
    output [31: 0]  avmm_csr_writedata,        
    output          avmm_csr_write,            
    input  [31: 0]  avmm_csr_readdata,      
    output [31: 0]  avmm_data_addr,          
    output          avmm_data_read,            
    output [31: 0]  avmm_data_writedata,        
    output          avmm_data_write,            
    input  [31: 0]  avmm_data_readdata,           
    input           avmm_data_waitrequest,          
    input           avmm_data_readdatavalid,          
    output [ 6: 0]  avmm_data_burstcount,
    output  [JUMPER_COUNT+12-1:0]   oOvDisable, 
    output         rjo_ready




);
assign rjo_ready=FlashRdSuccess;

wire   RJCCntlAddrReg;
wire   RJCCntlRdReg;
wire   RJCCntlWrDataReg;
wire   RJCCntlWrReg;
wire   RJCCntlRdData;
wire   RJCDataAddrReg;
wire   RJCDataRdReg;
wire   RJCDataWrDataReg;
wire   RJCDataWrReg;
wire   RJCDataRdData;
wire   RJCDataWaitReq;
wire   RJCDataRdValid;
wire   RJCDataBurstCntReg;

wire    [31: 0] UFMLdData;
wire    [31: 0] FlashOpAddr;
wire    [ 5: 0] FlashOpLen;
wire    [31: 0] FlashRJCWrData;
wire            FlashWriteEn;
wire            FlashEraseEn;
wire            FlashReadEn;
wire            FlashWrBusy;
wire            FlashRdBusy;
wire            FlashEraseBusy;
wire            FlashWrSuccess;
wire            FlashRdSuccess;
wire            FlashEraseSuccess;
wire    [5: 0]  UFMOpWriteCnt;
wire    [5: 0]  ReadCnt;
wire            loaddataen;

RJO_CSR 
  #(
        .JUMPER_COUNT  (JUMPER_COUNT),
	.SIGNATURE     (32'h2443_4A52) 
   
    )RJC_CSR_inst
(

    .Clock                       ( Clock                   ),
    .Reset                       ( Reset                   ),
	 .FM_VAL_DBG_JUMPER_EN        ( FM_VAL_DBG_JUMPER_EN    ),
	 .iT_Reset                    ( T_Reset                 ),
	 .iPLTRST_N                   ( iPLTRST_N               ),
    .iSlpS3                      ( iSlpS3                  ),
	 .iAUX_PWRGD_CPU              ( iAUX_PWRGD_CPU          ), 
    
    .iCPU0_MEM_Done              (  iCPU0_MEM_Done         ),
    .iCPU1_MEM_Done              (  iCPU1_MEM_Done         ),
    .CurrentValue                (  JumperOut              ),
	 .JumperIn                    (  JumperIn               ),	 
	 .invalid_access              (  invalid_access         ),
	 .FM_TTK_SPI_EN_RJC_N_Override      (  FM_TTK_SPI_EN_RJC_N_Override      ),
	 .PFR_DEBUG_JUMPER_RJC_N_Override   (  PFR_DEBUG_JUMPER_RJC_N_Override   ),
	 .PFR_FORCE_RECOVERY_RJC_N_Override (  PFR_FORCE_RECOVERY_RJC_N_Override ),
	 .FM_TTK_SPI_EN_RJC_N_Value         (  FM_TTK_SPI_EN_RJC_N_Value         ),
	 .PFR_DEBUG_JUMPER_RJC_N_Value      (  PFR_DEBUG_JUMPER_RJC_N_Value      ),
	 .PFR_FORCE_RECOVERY_RJC_N_Value    (  PFR_FORCE_RECOVERY_RJC_N_Value    ),
    //avmm intf connect to I2C slave
    .avmm_address                ( avmm_address         ),
    .avmm_write                  ( avmm_write           ),
    .avmm_writedata              ( avmm_writedata       ),
    .avmm_read                   ( avmm_read            ),
    .avmm_readdata               ( avmm_readdata        ),
    .avmm_readdatavalid          ( avmm_readvalid       ),
    .avmm_waitrequest            ( avmm_waitrequest     ),
    .avmm_byteenable             ( avmm_byteenable      ),
    //side band signals connect to flash
	  .UFMLdData                  ( UFMLdData               ),
    .FlashOpAddr                 ( FlashOpAddr             ),
	  .FlashOpLen                 ( FlashOpLen              ),
	  .FlashRJCWrData             ( FlashRJCWrData          ),
	  .FlashWriteEn               ( FlashWriteEn            ),
	  .FlashEraseEn               ( FlashEraseEn            ),
	  .FlashReadEn                ( FlashReadEn             ),
	  .FlashWrBusy                ( FlashWrBusy             ),
	  .FlashRdBusy                ( FlashRdBusy             ),
	  .FlashEraseBusy             ( FlashEraseBusy          ),
	  .FlashWrSuccess             ( FlashWrSuccess          ),
	  .FlashRdSuccess             ( FlashRdSuccess          ),
	  .FlashEraseSuccess          ( FlashEraseSuccess       ),
	  .loaddataen                 ( loaddataen              ),
	  .FlashError                 (),
    .RSU_FlashBusy                (RSU_FlashBusy            ), 
	  .UFMOpWriteCnt              ( UFMOpWriteCnt           ),
	.ReadCnt                    ( ReadCnt                 ),
	 .bidin			     ( bidin			),
	 .bidout    		     ( bidout                   ),
     .oOvDis                     (  oOvDisable                 )


);

RJO_FlashCtrl 
  #(
        .JUMPER_COUNT  (JUMPER_COUNT) 
   
    )RJO_FlashCtrl_inst
(
    .Clock                 ( Clock                    ),
    .Reset                 ( Reset                    ),
    .RSU_FlashBusy         (RSU_FlashBusy             ),
    .FlashRJCWrData        ( FlashRJCWrData           ),
	  .FlashOpAddr           ( FlashOpAddr             ),
    .FlashOpLen            ( FlashOpLen               ),
    .FlashOpRd             ( FlashReadEn              ),
    .FlashOpWr             ( FlashWriteEn             ),
    .FlashOpEr             ( FlashEraseEn             ),
    .FlashRdBusy           ( FlashRdBusy              ),
	  .FlashWrBusy           ( FlashWrBusy             ),
    .FlashEraseBusy        ( FlashEraseBusy           ),
    .FlashRdSuccess           ( FlashRdSuccess           ),
	  .FlashWrSuccess           ( FlashWrSuccess          ),
	  .FlashEraseSuccess           ( FlashEraseSuccess       ),
	  .ReadCnt               ( ReadCnt                 ),
	  .FlashError            (                         ),
	  .WriteCnt              ( UFMOpWriteCnt           ),
	  .UFMLdData             ( UFMLdData               ),
	  .loaddataen            (loaddataen               ),
  //connect to internal flash
      .CntlAddrReg        ( avmm_csr_addr           ),   
      .CntlRdReg          ( avmm_csr_read           ),     
      .CntlWrDataReg      ( avmm_csr_writedata      ), 
      .CntlWrReg          ( avmm_csr_write          ),     
      .CntlRdData         ( avmm_csr_readdata       ),    
      .DataAddrReg        ( avmm_data_addr          ),   
      .DataRdReg          ( avmm_data_read          ),     
      .DataWrDataReg      ( avmm_data_writedata     ), 
      .DataWrReg          ( avmm_data_write         ),     
      .DataRdData         ( avmm_data_readdata      ),    
      .DataWaitReq        ( avmm_data_waitrequest   ),   
      .DataRdValid        ( avmm_data_readdatavalid ),   
      .DataBurstCntReg    ( avmm_data_burstcount    )
	 
);
endmodule
